package initialize

import (
	"fmt"
	"ginBasic/global"
	"gopkg.in/ini.v1"
	"os"
	"strings"
)

func InitConfig() {
	global.Config, err = ini.LooseLoad("./conf/app.ini")
	if err != nil {
		fmt.Printf("Fail to read file: %v", err)
		os.Exit(1)
	}
}

// 获取配置内容 str格式：mysql.ip
func Config(str string) (strValue string) {

	if !strings.ContainsRune(str, '.') {
		panic("Please enter the correct format")
	}
	arr := strings.Split(str, ".") // 根据空格进行切割
	if arr[0] == "" || arr[1] == "" {
		panic("Please enter the correct format")
	}
	strValue = global.Config.Section(arr[0]).Key(arr[1]).String()
	return
}
